<%@page import="org.jeecgframework.web.util.StaticValue"%>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
<head>
	<title>批量生成巡检计划</title>
	<t:base type="jquery,easyui,tools,DatePicker"></t:base>
	<script type="text/javascript" src="plug-in/ckfinder/ckfinder.js"></script>
	<script type="text/javascript">
		function showMask(){
			lockmask(true);
		}
	</script>
</head>
<body>
<t:formvalid formid="generatePlan" action="zyInspectionPlanController.do?doAdd" dialog="true" usePlugin="password" layout="table" tiptype="1" beforeSubmit="showMask" callback="hideMask"
	btnsub="btn_sub"  >
	<input type="hidden" value="${equipmentIds }" name="equipmentIds" />
	<span>巡检计划信息</span>
	<table>
		<tr>
			<td>
				<label>计划巡检月份:</label>
			</td>
			<td>
				<span><t:dictSelect field="ipMonth" typeGroupCode="<%=StaticValue.DIC_IP_MONTH %>" hasPleaseSelect="false" /></span>
			</td>
			<td>
				<label>巡检单位:</label>
			</td>
			<td>
				<span>
					<select name="company" id="company">
						<option value="">---请选择--- </option>
						<c:forEach items="${tsDeparts }" var="depart">
							<option value="${depart.orgCode }">${depart.shortname }</option>
						</c:forEach>
					</select>
				</span>
			</td>
		</tr>
		<tr>
			<td>
				<label>光路要求:</label>
			</td>
			<td>
				<span><t:dictSelect field="lightPath" typeGroupCode="<%=StaticValue.DIC_LIGHT_PATH %>" hasPleaseSelect="false" /></span>
			</td>
			<td>
				<label>巡检负责人:</label>
			</td>
			<td>
				<input name="contacter.id" type="hidden" id="contacterId" />
				<input name="name" class="inputxt" id="contacterName" readonly="readonly" datatype="*" nullmsg="当前巡检单位巡检负责人为空，请重新选择" />
			</td>
		</tr>
		<tr>
			<td>
				<label>巡检负责人电话:</label>
			</td>
			<td>
				<span id="contacterCellPhone"></span>
			</td>
			<td>
				<label>巡检负责人邮箱:</label>
			</td>
			<td>
				<span id="contacterEmail"></span>
			</td>
		</tr>
		<tr>
			<td>
				<label>其他要求:</label>
			</td>
			<td>
				<span><textarea name="remarks" rows="6" cols="50" maxlength="400" datatype="*1-400"></textarea></span>
			</td>
			<td>
				<label></label>
			</td>
			<td>
				<span></span>
			</td>
		</tr>
	</table>
	<input type="hidden" id="btn_sub" />
</t:formvalid>
</body>
<script type="text/javascript">
$(function(){
	$("select[name='company']").change(function(){
		if($(this,"option:selected").val() != ""){
			$.ajax({
				url : "zyCommonController.do?queryTPServerBusinessr",
				data : {
					"orgCode" : $(this).val(),
					"contactPosition" : '<%=StaticValue.DIC_CONTACT_POSITION_TP_SERVER_BUSINESSR%>'
					},
				cache : false,
				dataType : 'json',
				type : 'POST',
				success : function(data){
					if(data.success){
						var obj = data.obj[0];
						if(obj){
							setContacter(obj.id, obj.name, obj.cellphone1 + (obj.cellphone2==""?"":("/"+obj.cellphone2)),obj.email);
						}else{
							setContacter();
						}
					}
				}
			});
		}else{
			setContacter();
		}
	});
	selectCurrMonth();
	$("select[name='ipMonth']").on('change',function(){
			console.log("$(this).val()"+$(this).val());
		if(parseInt($(this).val()) < parseInt('${currMonth}')){
			console.log('${currMonth}');
			selectCurrMonth();
			tip("所选月份不应小于当前月,已置为当前月份");
		}
	});
	setTimeout(function(){
		if(top.myWindow == undefined){
			tip("获取设备ID失败，请重新操作");
			setTimeout(function(){
				frameElement.api.close();
			},3000);
		}else{
			var datas = top.myWindow.$("#zyGenerateInspectionPlanList").datagrid("getSelections");
			var equipmentIdsArr = new Array();
			$(datas).each(function(i,item){
				equipmentIdsArr.push(item.id);
			});
			if(equipmentIdsArr.length == 0){
				tip("获取设备ID失败，请重新操作");
				setTimeout(function(){
					frameElement.api.close();
				},2000);
			}
			$("input[name='equipmentIds']").val(equipmentIdsArr.join(","));
		}
	},1000);//一秒延时，等待dialog init 初始化 myWindow
	function selectCurrMonth(){
		$("select[name='ipMonth']").find("option[value='"+'${currMonth}'+"']").attr("selected","selected");
	}
});
function setContacter(id,name,cellPhone,email){
	if(id == undefined || id == ""){
		$("#contacterId").val("");
		$("#contacterName").val("");
		$("#contacterCellPhone").html("");
		$("#contacterEmail").html("");
	}else{
		$("#contacterId").val(id);
		$("#contacterName").val(name);
		$("#contacterCellPhone").html(cellPhone);
		$("#contacterEmail").html(email);
	}
}
</script>
